﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Liger.Web.UI
{
    public class GridColumn : JObjectBase
    {
        public GridColumn()
            : this(null)
        {
        }
        public GridColumn(string name)
            : base()
        {
            this.Visible = true;
            this.Name = name;
            this.Align = "left";
            this.Type = "text";
        }

        /// <summary>
        /// 是否可视
        /// </summary>
        public bool? Visible
        {
            get;
            set;
        }
        /// <summary>
        /// 绑定列名
        /// </summary>
        public string Name 
        { 
            get; 
            set; 
        }
        /// <summary>
        /// 显示列名
        /// </summary>
        public string Display
        {
            get;
            set;
        }
        /// <summary>
        /// 对齐
        /// </summary>
        public string Align
        {
            get;
            set;
        }
        /// <summary>
        /// 宽度
        /// </summary>
        public string Width
        {
            get;
            set;
        }
        /// <summary>
        /// 最新宽度
        /// </summary>
        public string MinWidth
        {
            get;
            set;
        }
        /// <summary>
        /// 最大宽度
        /// </summary>
        public string MaxWidth
        {
            get;
            set;
        }

        /// <summary>
        /// 渲染器
        /// </summary>
        public Func<string> Render
        {
            get;
            set;
        }
        /// <summary>
        /// 列类型
        /// </summary>
        public string Type
        {
            get;
            set;
        }
        /// <summary>
        /// 格式化
        /// </summary>
        public string Format
        {
            get;
            set;
        }
        /// <summary>
        /// 是否可以排序
        /// </summary>
        public bool? IsSort
        {
            get;
            set;
        }
        /// <summary>
        /// 编辑器
        /// </summary>
        public GridColumnEditor Editor
        {
            get;
            set;
        }
         
        public IList<GridColumn> Columns
        {
            get;
            set;
        }


        public IList<GridColumn> VisibleColumns
        {
            get
            {
                if (Columns == null) return null;
                return Columns.Where(c => c.Visible.HasValue && c.Visible.Value).ToList();
            }
        }
    }
}
